package barney.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import barney.excepcion.DAOExcepcion;
import barney.negocio.SeguridadUsuario;

/**
 * Servlet implementation class RegistrarUsuario
 */
@WebServlet("/RegistrarUsuarioServlet")
public class RegistrarUsuarioServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistrarUsuarioServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String a = request.getParameter("txtNombres");
		String b = request.getParameter("txtPaterno");
		String c = request.getParameter("txtMaterno");
		String d = request.getParameter("txtUsuario");
		String z = request.getParameter("txtPassword1");
		String f = request.getParameter("txtCorreo");
		String g = request.getParameter("txtTelefono");
		String h = request.getParameter("RadioSexo");
		String i = request.getParameter("listDep");
					
		System.out.println("USUARIO INGRESADO:");
		System.out.println(a);
		System.out.println(b);
		System.out.println(c);
		System.out.println(d);
		System.out.println(z);
		System.out.println(f);
		System.out.println(g);
		System.out.println(h);
		System.out.println(i);
		
		//Llamamos a la clase NEGOCIO
		SeguridadUsuario neg = new SeguridadUsuario();
		
		try{
			neg.insertarUsuario(a, b, c, d, z, f, g, h, i);	
			RequestDispatcher rd = request.getRequestDispatcher("/usuario_registrar.jsp");
			rd.forward(request, response);
		}catch(DAOExcepcion e){
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");	
			rd.forward(request, response);
		}
				
	}

}
